﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;

namespace Wulong.Phone.Utils
{
    public class SortableObservableCollection<T> : ObservableCollection<T>
    {
        // This will use Comparer<T>.Default   
        public void Sort()
        {
            Sort(0, Count, null);
        }
        // Pass custom comparer to Sort method  
        public void Sort(IComparer<T> comparer)
        {
            Sort(0, Count, comparer);  
        }
        // Use this method to sort part of a collection  
        public void Sort(int index, int count, IComparer<T> comparer)
        {
            ((List<T>) Items).Sort(index, count, comparer);
            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }
    }
}
